<?php
/**
 * 用户控制类
 * @author yaoli<yaoli@pateo.com.cn>
 * @version 1.0 add by yaoli<yaoli@pateo.com.cn> 
 */
class user extends ActionBase1 {
	
	function init() {
	
	}
	
	/**
	 * 动作
	 *
	 * @see AActionBase::action()
	 */
	public function action() {
		
		show404 ( "不存在的方法！" );
	}
	
	public function checkuser() {
		
		
		// ASH校验
		filter::checkformhash ( $this->data ['request'] ['HASH_CODE'] );
		
		$result = load_model ( "bcs", 0 )->checkuser ( $this->data ['request'] ['phone'], $this->data ['request'] ['pwd'] );
		
		if ( $result->checkVo->status->code == 100 && $result->checkVo->vhlUserVo->id) {
			global $_SGLOBAL;
			$result = $this->saveuser ( 'user', $result->checkVo->vhlUserVo->id );
			
			if ($result) {
				#showSuc ( "登录成功!",'/' );
				header("Location:".'/');
			}
			// howSuc("登录成功!",url("radio/radio/program",null,0));
		} else {
			show404 ( "账号或密码错误 !" );
		}
	}
	
	public function checkvin(){
		if(isset($this->data['request']['vincode'])){
			$this->savevhl($this->data['request']['vincode']);
		}
			header("Location:"."/");
	}
	
	public function getvhl(){
		return (cache::getdata ( "vhl", 'cookie' ));
	}
	
	public function savevhl($vincode){
		return (cache::savedata ( "vhl", $vincode,'cookie' ));
	}
	
	public function saveuser($name, $data) {
		return (cache::savedata ( $name, $data, 'cookie' ));
	}
	
	public static function getuser($name) {
		return (cache::getdata ( $name, 'cookie' ));
	}
	
	//获取用户初始数据
	public static function getuserinfo(){
		$user = load_model("bcs",0)->getuserinfo(1);
		return $user;
	}
	
	public static function logout() {
		
		cache::deletedata ( "user", 'cookie' );
		cache::deletedata ( "vhl", 'cookie' );
		showSuc ( "成功登出!","/" );
	}
	
	public  function setlan(){
		
		$lan = $this->data['request']['lan'];
		$lan = isset($lan)?$lan:'ch';
		cache::savedata ( "lan", $lan, 'cookie',3600*360);
		header("Location:/");
	}
	
	public  function getlan(){
		return (cache::getdata ( "lan", 'cookie' ));
	}

}
